<?php
require("includes/basic.php");

if($userType=='D')
{
	$gettask=mysql_query("select * from task_assigned_to tt, task_status ts, task_master tm, project_master pm, status_type st where tt.task_id=tm.task_id and tt.task_id=ts.task_id and tm.project_id=pm.project_id and tt.task_assigned_to=$userId and ts.task_status=st.status_id");
}
else
{
$gettask=mysql_query("select * from task_master tm, task_assigned_to tt, task_status ts, project_master pm, status_type st, user_master um  where tt.task_id=tm.task_id and tt.task_id=ts.task_id and tm.project_id=pm.project_id and pm.project_created_by=$customerid and ts.task_status=st.status_id and tt.task_assigned_to=um.user_id");
}
$class="evenrowbg";
?>
<table width="100%" class='list'>
<tr><th>Project</th><th>Task</th><?php if($userType !='D') { echo "<th>Resource</th>"; } ?><th>Status</th><th>Start time</th><th>End time</th><th>Total time</th></tr>
<?php
while($tasks=mysql_fetch_array($gettask))
{
if($class=="evenrowbg")
	{
		$class="oddrowbg";
	}
	else
	{
		$class="evenrowbg";
	}
	$taskid=$tasks['task_id'];
$taskname=$tasks['task_title'];
$project=$tasks['project_name'];
$status=$tasks['status'];
$assignedto=$tasks['task_assigned_to'];

$endtime="Pending";
$totaltime="Task Pending";

$getstime=mysql_query("select min(UNIX_TIMESTAMP(start_time)), start_time from task_timeline where task_id =$taskid and created_by=$assignedto");

$getstimer=mysql_fetch_array($getstime);
extract($getstimer);
if($getstimer['start_time'] != null)
{
$starttime=$getstimer['start_time'];
}
else
{
$starttime="Not Started";
}
if($status=="closed")
{
$getetime=mysql_query("select max(UNIX_TIMESTAMP(end_time)), end_time from task_timeline where task_id = $taskid and created_by = $assignedto");
$getetimer=mysql_fetch_array($getetime);
extract($getetimer);
$endtime=$getetimer['end_time'];
$gettotaltime=mysql_query("select round(sum(diff)) from task_timeline where task_id = $taskid and created_by = $assignedto");
$gettotaltimer=mysql_fetch_array($gettotaltime);
extract($gettotaltimer);
$totaltime=$gettotaltimer['round(sum(diff))']." hrs";
}
echo "<tr class='$class'><td>$project</td><td>$taskname</td>";
if($userType !='D') {
$resource=$tasks['first_name']." ".$tasks['last_name'];
echo "<td>$resource</td>";
}
echo "<td>$status</td><td>$starttime</td><td>$endtime</td><td>$totaltime</td></tr>";
}
?>
</table>